﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using BySoft.Web.Utility;
using System.Data;
using BySoft.Server.Business;
using System.Web;
using BySoft.Server.Common.Enum;
using BySoft.Server.Common;
using BySoft.Server.Common.Entity;
using ZCZP.Web.Site;

namespace BySoft.Web.Site.OutSource
{
    public partial class OutMatReturnView : AuthBasePage
    {

      
      
        #region 初始化及绑定控件
        private void InitData()
        {
			string strCode = HttpUtility.UrlDecode(UIHelper.GetQueryStringValue("id").Trim());
			InitHead(strCode);
            InitBody(strCode);
        }

        private void InitHead(string strCode)
        {
            DataTable dt = BsOutmatreturn.SelectHeadData(strCode);
            DBtoControlHead(this.Page, dt, tBase, @"../OutOrder/OutMatReturnList.aspx");
            DataRow row = dt.Rows[0];
            hidOutOrderID.Value = CommonMethod.GetString(row["OutOrderID"]);
            //hdCode.Value = CommonMethod.GetString(row["BillID"]);

        }

        private void InitBody(string strCode)
        {
            DataTable dt = BsOutmatreturn.SelectDetailData(strCode);
            foreach (DataRow dr in dt.Rows)
            {
                string sendID = hidOutOrderID.Value;
                string materialID = dr["MaterialID"].ToString();
                DataTable dtCanBack = BsOutorder.SelectSendDetailCanReturnNum(strCode, sendID, materialID);
                if (dtCanBack.Rows.Count > 0)
                {

                    DataRow dr0 = dtCanBack.Rows[0];
                    dr["SendNum"] = dr0["SendNum"];
                    dr["CanBackNum"] = dr0["CanBackNum"];
                }
                else
                {
                    dr["SendNum"] = dr["Nums"];
                    dr["CanBackNum"] = dr["Nums"];
                }


            }
              BindData(dt);
        }
        #endregion

        #region 控件事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
				grdResult.Style.Add("word-break", "keep-all");
                grdResult.Style.Add("word-wrap", "normal");
                InitData();
            }
			UIHelper.RunScript(this.Page, "Refreashtab();");
        }

		private void BindData(DataTable dt)
        {
            if (dt.Rows.Count > 0)
            {
                grdResult.DataSource = dt;
                grdResult.DataBind();
            }
            else
            {
                UIHelper.BindEmptyGridView(grdResult, dt);
            }
            UIHelper.RunScript(this.Page, "iframeAutoFit();");
        }
		#endregion
    }
}

